class_name BaseBlock
extends RefCounted

var type: int
var uv: Array[PackedVector2Array]
var vertex: Array[PackedVector3Array]
var indice: Array[PackedInt32Array]

func generate():
	pass

func generate_indice():
	var idx1:PackedInt32Array
	var idx2:PackedInt32Array
	idx1.push_back(0);idx1.push_back(1);idx1.push_back(2)
	idx1.push_back(2);idx1.push_back(1);idx1.push_back(3)
	idx2.push_back(0);idx2.push_back(2);idx2.push_back(1)
	idx2.push_back(1);idx2.push_back(2);idx2.push_back(3)
	for i in 6:
		indice.push_back(idx1)
		indice.push_back(idx1)
		indice.push_back(idx1)
		indice.push_back(idx2)
		indice.push_back(idx2)
		indice.push_back(idx2)


func generate_vertex():

	var v0:PackedVector3Array
	v0.push_back(Vector3(0,1,0));v0.push_back(Vector3(1,1,0));
	v0.push_back(Vector3(0,1,1));v0.push_back(Vector3(1,1,1));
	vertex.push_back(v0.duplicate())
	v0.clear()
	v0.push_back(Vector3(0,1,0));v0.push_back(Vector3(0,1,1));
	v0.push_back(Vector3(0,0,0));v0.push_back(Vector3(0,0,1));
	vertex.push_back(v0.duplicate())
	v0.clear()
	v0.push_back(Vector3(1,1,0));v0.push_back(Vector3(0,1,0));
	v0.push_back(Vector3(1,0,0));v0.push_back(Vector3(0,0,0));
	vertex.push_back(v0.duplicate())
	v0.clear()
	v0.push_back(Vector3(1,1,0));v0.push_back(Vector3(1,1,1));
	v0.push_back(Vector3(1,0,0));v0.push_back(Vector3(1,0,1));
	vertex.push_back(v0.duplicate())
	v0.clear()
	v0.push_back(Vector3(1,1,1));v0.push_back(Vector3(0,1,1));
	v0.push_back(Vector3(1,0,1));v0.push_back(Vector3(0,0,1));
	vertex.push_back(v0.duplicate())
	v0.clear()
	v0.push_back(Vector3(0,0,0));v0.push_back(Vector3(1,0,0));
	v0.push_back(Vector3(0,0,1));v0.push_back(Vector3(1,0,1));
	vertex.push_back(v0.duplicate())

func get_uv(p_id)->PackedVector2Array:
	return Tools.uv_map.uvs[p_id]

func get_block_mesh():
	var res:Array
	res.push_back(indice)
	res.push_back(vertex)
	res.push_back(uv)
	return res
